package com.kui.springcloud.controller;

import com.kui.springcloud.model.Dept;
import com.kui.springcloud.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 风 on 2021/5/24.
 */
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @Autowired
    private DiscoveryClient client;
    @PostMapping("/add")
    public boolean addDept(Dept dept){
        return deptService.addDept(dept);
    }
    @GetMapping("/{id}")
    public Dept queryById(@PathVariable  Long id){
        return deptService.queryById(id);
    }
    @GetMapping("/list")
    public List<Dept> findAll(){
        return deptService.findAll();
    }
    @GetMapping("/desc")
    public Object getDesc(){
        List<ServiceInstance> instances = client.getInstances("SPRINGCLOUD-PROVIDER");
        instances.forEach(e->{
            System.out.println("host" +e.getHost()+"\n"
                    +e.getUri()+"url");
        });
        return instances;
    }

}
